package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.CommentReply;
import cn.wolfcode.trip.base.mapper.CommentReplyMapper;
import cn.wolfcode.trip.base.query.CommentReplyQueryObj;
import cn.wolfcode.trip.base.service.ICommentReplyService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class CommentReplyServiceImpl implements ICommentReplyService{
    @Autowired
    private CommentReplyMapper commentReplyMapper;

    public PageInfo selectByStrategyCommentId(CommentReplyQueryObj qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<CommentReply> list = commentReplyMapper.selectByStrategyCommentId(qo);
        return new PageInfo(list);
    }

    public int selectCountByStrategyCommentId(CommentReplyQueryObj qo) {
        return commentReplyMapper. selectCountByStrategyCommentId(qo);
    }

    public void saveReply(CommentReply commentReply) {
        commentReply.setCreateTime(new Date());
        commentReplyMapper.insert(commentReply);
    }

    @Override
    public PageInfo listRepiersInfo(CommentReplyQueryObj qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize(),qo.getOrderBy());
        List<CommentReply> commentReplies=commentReplyMapper.selectRepilersInfo(qo);
        return new PageInfo(commentReplies);
    }

    @Override
    public void updateState(int state, Long userId) {
        commentReplyMapper.updateState(state,userId);
    }

    @Override
    public void updateLikeNum(Long relationId) {
        commentReplyMapper.updateLikeNum(relationId);
    }

}
